package de.hska.algo.labor2010.strecken;

import java.util.ArrayList;

/**
 * holds {@link Line} s in a grid, half of the lines horizontal, half of the
 * lines vertical
 * 
 * @author Daniela Brenner
 * @version 1.0
 */
public class GridLines implements LinesGenerator {
	/**
	 * @uml.property name="lines"
	 * @uml.associationEnd multiplicity="(0 -1)"
	 *                     elementType="de.hska.algo.labor2010.strecken.Line"
	 */
	private ArrayList<Line> lines;

	public ArrayList<Line> getLines() {
		return lines;
	}

	public GridLines(int n) {
		lines = new ArrayList<Line>(n);
		create(n);
	}

	@Override
	public void create(int n) {

		double x = 0;
		double y = 0;
		double step = 10;
		double max = n/2 *step -step;
		
		for (int i = 0; i < n / 2; i++) {
			lines.add(new Line(x + i * step, y, x + i * step, y + max));
		}
		for (int i = 0; i < n / 2; i++) {
			lines.add(new Line(x, y + i * step, x + max, y + i* step));
		}
	}

	@Override
	public String toString() {
		String sth = "Lines\n";
		int i = 0;
		for (Line line : lines) {
			sth+= i + ": " + line.toString();
			i++;
		}
		return sth;

	}

}
